import * as mongoose from 'mongoose'
const Schema = mongoose.Schema

const mongoDB = 'mongodb://127.0.0.1/articles'
mongoose.connect(mongoDB, { useNewUrlParser: true, useUnifiedTopology: true })

const db = mongoose.connection

db.on('error', console.error.bind(console, 'MongoDB 连接错误：'))
db.once('open', () => {
	console.log('connect success')
})
console.log('connect')

const articleSchema = new Schema({
	nid: Number,
	aid: Number,
	title: String,
	notebookName: String,
	content: String,
})

const articlesTitleSchema = new Schema({
	nid: Number,
	aid: Number,
	title: String,
	notebookName: String,
})

export const article = mongoose.model('article', articleSchema)
export const articlesTitle = mongoose.model(
	'articlesTitle',
	articlesTitleSchema
)

